home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / dp / dp_main.s < prev    next >
Encoding:
Text File  |  1996-08-28  |  11.2 KB  |  693 lines

  1. ;
  2. ; Double-precision math interface library for ACE.
  3. ; Copyright (C) 1998 David Benn
  4. ; This program is free software; you can redistribute it and/or
  5. ; modify it under the terms of the GNU General Public License
  6. ; as published by the Free Software Foundation; either version 2
  7. ; of the License, or (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. ;
  18. ; Register a6 is preserved and restored by each routine
  19. ; since Sozobon C uses this as a link register.
  20. ; Author: David J Benn
  21. ;   Date: 11th February 1996,
  22. ;      16th August 1996,
  23. ;      29th September 1996,
  24. ;      1st,18th October 1996
  25. ;
  26.  
  27. TRUE    equ    -1
  28. FALSE    equ    0
  29.  
  30.     ; Basic functions.
  31.     xref    _LVOIEEEDPAbs
  32.     xref    _LVOIEEEDPAdd
  33.     xref    _LVOIEEEDPCeil
  34.     xref    _LVOIEEEDPCmp
  35.     xref    _LVOIEEEDPDiv
  36.     xref    _LVOIEEEDPFix
  37.     xref    _LVOIEEEDPFloor
  38.     xref    _LVOIEEEDPFlt
  39.     xref    _LVOIEEEDPMul
  40.     xref    _LVOIEEEDPNeg
  41.     xref    _LVOIEEEDPSub
  42.     xref    _LVOIEEEDPTst
  43.  
  44.     ; Transcendental functions.
  45.     xref    _LVOIEEEDPAsin
  46.     xref    _LVOIEEEDPAcos
  47.     xref    _LVOIEEEDPAtan
  48.     xref    _LVOIEEEDPSin
  49.     xref    _LVOIEEEDPCos
  50.     xref    _LVOIEEEDPTan
  51.     xref    _LVOIEEEDPSincos
  52.     xref    _LVOIEEEDPSinh
  53.     xref    _LVOIEEEDPCosh
  54.     xref    _LVOIEEEDPTanh
  55.     xref    _LVOIEEEDPExp
  56.     xref    _LVOIEEEDPFieee
  57.     xref    _LVOIEEEDPLog
  58.     xref    _LVOIEEEDPLog10
  59.     xref    _LVOIEEEDPPow
  60.     xref    _LVOIEEEDPSqrt
  61.     xref    _LVOIEEEDPTieee
  62.  
  63.     ; Miscellaneous external references.
  64.     xref    _AbsExecBase
  65.     xref    _LVOOpenLibrary
  66.     xref    _LVOCloseLibrary
  67.  
  68.     xref    _MathTransBase
  69.     xref    _LVOSPFieee    
  70.     xref    _LVOSPTieee    
  71.  
  72.     ; Exports.
  73.     xdef    _MathIeeeDoubBasBase
  74.     xdef    _MathIeeeDoubTransBase
  75.  
  76.     section    code, dp_code
  77.  
  78. ;************************************
  79.  
  80.     PUBLIC    _dp_open
  81.     ;
  82.     ; Open IEEE DP libraries x 2.
  83.     ;
  84. _dp_open:
  85.     move.l    a6,_a6
  86.  
  87.     movea.l _AbsExecBase,a6        
  88.  
  89.     ; Open basic library.
  90.     movea.l    #_ieeedoubbaslibname,a1
  91.     move.l    #34,d0
  92.     jsr     _LVOOpenLibrary(a6)
  93.     tst.l    d0
  94.     beq.s    _abort_dp_open
  95.     move.l    d0,_MathIeeeDoubBasBase
  96.  
  97.     ; Open transcendental library.
  98.     movea.l    #_ieeedoubtranslibname,a1
  99.     move.l    #34,d0
  100.     jsr     _LVOOpenLibrary(a6)
  101.     tst.l    d0
  102.     beq.s    _abort_dp_open
  103.     move.l    d0,_MathIeeeDoubTransBase
  104.     
  105.     ; Exit with success code (TRUE).
  106.     move.l    #TRUE,d0    ; okay.
  107.     bra.s    _exit_dp_open
  108.  
  109. _abort_dp_open:
  110.     move.l    #FALSE,d0    ; error.
  111.  
  112. _exit_dp_open:
  113.     movea.l    _a6,a6
  114.     
  115.     rts
  116.  
  117. ;************************************
  118.  
  119.     PUBLIC    _dp_close
  120.     ;
  121.     ; Close IEEE DP libraries x 2.
  122.     ;
  123. _dp_close:
  124.     move.l    a6,_a6
  125.  
  126.     tst.l    _MathIeeeDoubBasBase
  127.     beq.s    _exit_dp_close
  128.  
  129.     movea.l _AbsExecBase,a6
  130.  
  131.     move.l  _MathIeeeDoubBasBase,a1
  132.     jsr     _LVOCloseLibrary(a6)
  133.  
  134.     tst.l    _MathIeeeDoubTransBase
  135.     beq.s    _exit_dp_close
  136.  
  137.     move.l  _MathIeeeDoubTransBase,a1
  138.     jsr     _LVOCloseLibrary(a6)
  139.  
  140. _exit_dp_close:
  141.     movea.l    _a6,a6
  142.     
  143.     rts
  144.  
  145. ;************************************
  146.  
  147.     PUBLIC    _dp_longint_to_double
  148.     ;
  149.     ; Convert LONGINT to DOUBLE.
  150.     ;
  151. _dp_longint_to_double:
  152.     move.l    a6,_a6
  153.  
  154.     move.l    8(sp),d0        ; integer value.
  155.  
  156.     movea.l    _MathIeeeDoubBasBase,a6
  157.     jsr    _LVOIEEEDPFlt(a6)
  158.  
  159.     move.l    4(sp),a0        ; address of double result.
  160.     move.l    d0,(a0)+
  161.     move.l    d1,(a0)
  162.  
  163.     movea.l    _a6,a6
  164.     
  165.     rts
  166.  
  167. ;************************************
  168.  
  169.     PUBLIC    _dp_double_to_longint
  170.     ;
  171.     ; Convert DOUBLE to LONGINT.
  172.     ;
  173. _dp_double_to_longint:
  174.     move.l    a6,_a6
  175.  
  176.     move.l    8(sp),a1        ; address of double.
  177.     
  178.     move.l    (a1)+,d0
  179.     move.l    (a1),d1
  180.  
  181.     movea.l    _MathIeeeDoubBasBase,a6
  182.     jsr    _LVOIEEEDPFix(a6)
  183.  
  184.     move.l    4(sp),a0        ; address of integer result.
  185.     move.l    d0,(a0)
  186.  
  187.     movea.l    _a6,a6
  188.  
  189.     rts
  190.  
  191. ;************************************
  192.  
  193.     PUBLIC    _dp_single_to_double
  194.     ;
  195.     ; Convert SINGLE to DOUBLE.
  196.     ;
  197. _dp_single_to_double:
  198.     move.l    a6,_a6
  199.  
  200.     move.l    8(sp),d0        ; single value.
  201.  
  202.     movea.l    _MathTransBase,a6
  203.     jsr    _LVOSPTieee(a6)        ; FFP -> IEEE SP
  204.     movea.l    _MathIeeeDoubTransBase,a6    
  205.     jsr    _LVOIEEEDPFieee(a6)    ; IEEE SP -> IEEE DP
  206.  
  207.     move.l    4(sp),a0        ; address of double result.
  208.     move.l    d0,(a0)+
  209.     move.l    d1,(a0)
  210.  
  211.     movea.l    _a6,a6
  212.     
  213.     rts
  214.  
  215. ;************************************
  216.  
  217.     PUBLIC    _dp_double_to_single
  218.     ;
  219.     ; Convert DOUBLE to SINGLE.
  220.     ;
  221. _dp_double_to_single:
  222.     move.l    a6,_a6
  223.  
  224.     move.l    8(sp),a1        ; address of double.
  225.  
  226.     move.l    (a1)+,d0
  227.     move.l    (a1),d1
  228.  
  229.     movea.l    _MathIeeeDoubTransBase,a6
  230.     jsr    _LVOIEEEDPTieee(a6)    ; IEEE DP -> IEEE SP
  231.     movea.l    _MathTransBase,a6
  232.     jsr    _LVOSPFieee(a6)        ; IEEE SP -> FFP
  233.  
  234.     move.l    4(sp),a0        ; address of single result.
  235.     move.l    d0,(a0)
  236.  
  237.     movea.l    _a6,a6
  238.  
  239.     rts
  240.  
  241. ;************************************
  242.  
  243.     PUBLIC    _dp_add
  244.     ;
  245.     ; Add two DOUBLE values (result = op1 + op2).
  246.     ;
  247. _dp_add:
  248.     move.l    a6,_a6
  249.  
  250.     move.l    12(sp),a2        ; address of operand 2.
  251.     move.l    8(sp),a1        ; address of operand 1.
  252.  
  253.     move.l    (a2)+,d2
  254.     move.l    (a2),d3            
  255.  
  256.     move.l    (a1)+,d0
  257.     move.l    (a1),d1    
  258.  
  259.     movea.l    _MathIeeeDoubBasBase,a6
  260.     jsr    _LVOIEEEDPAdd(a6)
  261.  
  262.     move.l    4(sp),a0        ; address of result.    
  263.     move.l    d0,(a0)+
  264.     move.l    d1,(a0)
  265.  
  266.     movea.l    _a6,a6
  267.  
  268.     rts
  269.  
  270. ;************************************
  271.  
  272.     PUBLIC    _dp_sub
  273.     ;
  274.     ; Subtract two DOUBLE values (result = op1 - op2).
  275.     ;
  276. _dp_sub:
  277.     move.l    a6,_a6
  278.  
  279.     move.l    12(sp),a2        ; address of operand 2.
  280.     move.l    8(sp),a1        ; address of operand 1.
  281.  
  282.     move.l    (a2)+,d2
  283.     move.l    (a2),d3            
  284.  
  285.     move.l    (a1)+,d0
  286.     move.l    (a1),d1    
  287.  
  288.     movea.l    _MathIeeeDoubBasBase,a6
  289.     jsr    _LVOIEEEDPSub(a6)
  290.  
  291.     move.l    4(sp),a0        ; address of result.    
  292.     move.l    d0,(a0)+
  293.     move.l    d1,(a0)
  294.  
  295.     movea.l    _a6,a6
  296.  
  297.     rts
  298.  
  299. ;************************************
  300.  
  301.     PUBLIC    _dp_mul
  302.     ;
  303.     ; Mulitply two DOUBLE values (result = op1 * op2).
  304.     ;
  305. _dp_mul:
  306.     move.l    a6,_a6
  307.  
  308.     move.l    12(sp),a2        ; address of operand 2.
  309.     move.l    8(sp),a1        ; address of operand 1.
  310.  
  311.     move.l    (a2)+,d2
  312.     move.l    (a2),d3            
  313.  
  314.     move.l    (a1)+,d0
  315.     move.l    (a1),d1    
  316.  
  317.     movea.l    _MathIeeeDoubBasBase,a6
  318.     jsr    _LVOIEEEDPMul(a6)
  319.  
  320.     move.l    4(sp),a0        ; address of result.    
  321.     move.l    d0,(a0)+
  322.     move.l    d1,(a0)
  323.  
  324.     movea.l    _a6,a6
  325.  
  326.     rts
  327.  
  328. ;************************************
  329.  
  330.     PUBLIC    _dp_div
  331.     ;
  332.     ; Divide two DOUBLE values (result = op1 / op2).
  333.     ;
  334. _dp_div:
  335.     move.l    a6,_a6
  336.  
  337.     move.l    12(sp),a2        ; address of operand 2.
  338.     move.l    8(sp),a1        ; address of operand 1.
  339.  
  340.     move.l    (a2)+,d2
  341.     move.l    (a2),d3            
  342.  
  343.     move.l    (a1)+,d0
  344.     move.l    (a1),d1    
  345.  
  346.     movea.l    _MathIeeeDoubBasBase,a6
  347.     jsr    _LVOIEEEDPDiv(a6)
  348.  
  349.     move.l    4(sp),a0        ; address of result.    
  350.     move.l    d0,(a0)+
  351.     move.l    d1,(a0)
  352.  
  353.     movea.l    _a6,a6
  354.  
  355.     rts
  356.  
  357. ;************************************
  358.  
  359.     PUBLIC    _dp_cmp
  360.     ;
  361.     ; Compare two DOUBLE values.
  362.     ; Returns an integer:
  363.     ; 
  364.     ;     +1 if op1 > op2
  365.     ;     -1 if op1 < op2
  366.     ;      0 if op1 = op2
  367.     ;
  368. _dp_cmp:
  369.     move.l    a6,_a6
  370.  
  371.     move.l    12(sp),a2        ; address of operand 2.
  372.     move.l    8(sp),a1        ; address of operand 1.
  373.  
  374.     move.l    (a2)+,d2
  375.     move.l    (a2),d3            
  376.  
  377.     move.l    (a1)+,d0
  378.     move.l    (a1),d1    
  379.  
  380.     movea.l    _MathIeeeDoubBasBase,a6
  381.     jsr    _LVOIEEEDPCmp(a6)
  382.  
  383.     move.l    4(sp),a0        ; address of result.    
  384.     move.l    d0,(a0)
  385.  
  386.     movea.l    _a6,a6
  387.  
  388.     rts
  389.  
  390. ;************************************
  391.  
  392.     PUBLIC    _dp_pow
  393.     ;
  394.     ; Raise one DOUBLE to the power of another.
  395.     ; (result = op1 ^ op2).
  396.     ;
  397. _dp_pow:
  398.     move.l    a6,_a6
  399.  
  400.     move.l    12(sp),a2        ; address of operand 2.
  401.     move.l    8(sp),a1        ; address of operand 1.
  402.  
  403.     move.l    (a1)+,d0
  404.     move.l    (a1),d1        
  405.  
  406.     move.l    (a2)+,d2
  407.     move.l    (a2),d3
  408.  
  409.     movea.l    _MathIeeeDoubTransBase,a6
  410.     jsr    _LVOIEEEDPPow(a6)
  411.  
  412.     move.l    4(sp),a0        ; address of result.    
  413.     move.l    d0,(a0)+
  414.     move.l    d1,(a0)
  415.  
  416.     movea.l    _a6,a6
  417.  
  418.     rts
  419.  
  420. ;************************************
  421.  
  422.     PUBLIC    _dp_abs
  423.     ;
  424.     ; Return the absolute value of a DOUBLE.
  425.     ;
  426. _dp_abs:
  427.     move.l    a6,_a6
  428.  
  429.     move.l    8(sp),a1        ; address of operand.
  430.  
  431.     move.l    (a1)+,d0
  432.     move.l    (a1),d1    
  433.  
  434.     movea.l    _MathIeeeDoubBasBase,a6
  435.     jsr    _LVOIEEEDPAbs(a6)
  436.  
  437.     move.l    4(sp),a0        ; address of result.    
  438.     move.l    d0,(a0)+
  439.     move.l    d1,(a0)
  440.  
  441.     movea.l    _a6,a6
  442.  
  443.     rts
  444.  
  445. ;************************************
  446.  
  447.     PUBLIC    _dp_neg
  448.     ;
  449.     ; Return the negated value of a DOUBLE.
  450.     ;
  451. _dp_neg:
  452.     move.l    a6,_a6
  453.  
  454.     move.l    8(sp),a1        ; address of operand.
  455.  
  456.     move.l    (a1)+,d0
  457.     move.l    (a1),d1    
  458.  
  459.     movea.l    _MathIeeeDoubBasBase,a6
  460.     jsr    _LVOIEEEDPNeg(a6)
  461.  
  462.     move.l    4(sp),a0        ; address of result.    
  463.     move.l    d0,(a0)+
  464.     move.l    d1,(a0)
  465.  
  466.     movea.l    _a6,a6
  467.  
  468.     rts
  469.  
  470. ;************************************
  471.  
  472.     PUBLIC    _dp_ceil
  473.     ;
  474.     ; Return the least integer which is >= a DOUBLE.
  475.     ; Result is DOUBLE not LONGINT!
  476.     ;
  477. _dp_ceil:
  478.     move.l    a6,_a6
  479.  
  480.     move.l    8(sp),a1        ; address of operand.
  481.  
  482.     move.l    (a1)+,d0
  483.     move.l    (a1),d1    
  484.  
  485.     movea.l    _MathIeeeDoubBasBase,a6
  486.     jsr    _LVOIEEEDPCeil(a6)
  487.  
  488.     move.l    4(sp),a0        ; address of result.    
  489.     move.l    d0,(a0)+
  490.     move.l    d1,(a0)
  491.  
  492.     movea.l    _a6,a6
  493.  
  494.     rts
  495.  
  496. ;************************************
  497.  
  498.     PUBLIC    _dp_floor
  499.     ;
  500.     ; Return the largest integer which is <= a DOUBLE.
  501.     ; Result is DOUBLE not LONGINT!
  502.     ;
  503. _dp_floor:
  504.     move.l    a6,_a6
  505.  
  506.     move.l    8(sp),a1        ; address of operand.
  507.  
  508.     move.l    (a1)+,d0
  509.     move.l    (a1),d1    
  510.  
  511.     movea.l    _MathIeeeDoubBasBase,a6
  512.     jsr    _LVOIEEEDPFloor(a6)
  513.  
  514.     move.l    4(sp),a0        ; address of result.    
  515.     move.l    d0,(a0)+
  516.     move.l    d1,(a0)
  517.  
  518.     movea.l    _a6,a6
  519.  
  520.     rts
  521.  
  522. ;************************************
  523.  
  524.     PUBLIC    _dp_sin
  525.     ;
  526.     ; Return the sine of a DOUBLE (radians).
  527.     ;
  528. _dp_sin:
  529.     move.l    a6,_a6
  530.  
  531.     move.l    8(sp),a1        ; address of operand.
  532.  
  533.     move.l    (a1)+,d0
  534.     move.l    (a1),d1    
  535.  
  536.     movea.l    _MathIeeeDoubTransBase,a6
  537.     jsr    _LVOIEEEDPSin(a6)
  538.  
  539.     move.l    4(sp),a0        ; address of result.    
  540.     move.l    d0,(a0)+
  541.     move.l    d1,(a0)
  542.  
  543.     movea.l    _a6,a6
  544.  
  545.     rts
  546.  
  547. ;************************************
  548.  
  549.     PUBLIC    _dp_cos
  550.     ;
  551.     ; Return the cosine of a DOUBLE (radians).
  552.     ;
  553. _dp_cos:
  554.     move.l    a6,_a6
  555.  
  556.     move.l    8(sp),a1        ; address of operand.
  557.  
  558.     move.l    (a1)+,d0
  559.     move.l    (a1),d1    
  560.  
  561.     movea.l    _MathIeeeDoubTransBase,a6
  562.     jsr    _LVOIEEEDPCos(a6)
  563.  
  564.     move.l    4(sp),a0        ; address of result.    
  565.     move.l    d0,(a0)+
  566.     move.l    d1,(a0)
  567.  
  568.     movea.l    _a6,a6
  569.  
  570.     rts
  571.  
  572. ;************************************
  573.  
  574.     PUBLIC    _dp_tan
  575.     ;
  576.     ; Return the tangent of a DOUBLE (radians).
  577.     ;
  578. _dp_tan:
  579.     move.l    a6,_a6
  580.  
  581.     move.l    8(sp),a1        ; address of operand.
  582.  
  583.     move.l    (a1)+,d0
  584.     move.l    (a1),d1    
  585.  
  586.     movea.l    _MathIeeeDoubTransBase,a6
  587.     jsr    _LVOIEEEDPTan(a6)
  588.  
  589.     move.l    4(sp),a0        ; address of result.    
  590.     move.l    d0,(a0)+
  591.     move.l    d1,(a0)
  592.  
  593.     movea.l    _a6,a6
  594.  
  595.     rts
  596.  
  597. ;************************************
  598.  
  599.     PUBLIC    _dp_exp
  600.     ;
  601.     ; Return e to the power of a DOUBLE.
  602.     ;
  603. _dp_exp:
  604.     move.l    a6,_a6
  605.  
  606.     move.l    8(sp),a1        ; address of operand.
  607.  
  608.     move.l    (a1)+,d0
  609.     move.l    (a1),d1    
  610.  
  611.     movea.l    _MathIeeeDoubTransBase,a6
  612.     jsr    _LVOIEEEDPExp(a6)
  613.  
  614.     move.l    4(sp),a0        ; address of result.    
  615.     move.l    d0,(a0)+
  616.     move.l    d1,(a0)
  617.  
  618.     movea.l    _a6,a6
  619.  
  620.     rts
  621.  
  622. ;************************************
  623.  
  624.     PUBLIC    _dp_log
  625.     ;
  626.     ; Return the natural logarithm (base e) of a DOUBLE.
  627.     ;
  628. _dp_log:
  629.     move.l    a6,_a6
  630.  
  631.     move.l    8(sp),a1        ; address of operand.
  632.  
  633.     move.l    (a1)+,d0
  634.     move.l    (a1),d1    
  635.  
  636.     movea.l    _MathIeeeDoubTransBase,a6
  637.     jsr    _LVOIEEEDPLog(a6)
  638.  
  639.     move.l    4(sp),a0        ; address of result.    
  640.     move.l    d0,(a0)+
  641.     move.l    d1,(a0)
  642.  
  643.     movea.l    _a6,a6
  644.  
  645.     rts
  646.  
  647. ;************************************
  648.  
  649.     PUBLIC    _dp_sqrt
  650.     ;
  651.     ; Return the square root of a DOUBLE.
  652.     ;
  653. _dp_sqrt:
  654.     move.l    a6,_a6
  655.  
  656.     move.l    8(sp),a1        ; address of operand.
  657.  
  658.     move.l    (a1)+,d0
  659.     move.l    (a1),d1    
  660.  
  661.     movea.l    _MathIeeeDoubTransBase,a6
  662.     jsr    _LVOIEEEDPSqrt(a6)
  663.  
  664.     move.l    4(sp),a0        ; address of result.    
  665.     move.l    d0,(a0)+
  666.     move.l    d1,(a0)
  667.  
  668.     movea.l    _a6,a6
  669.  
  670.     rts
  671.  
  672. ;************************************
  673.         
  674.     section    data, dp_data
  675.  
  676. _ieeedoubbaslibname:    dc.b    'mathieeedoubbas.library',0
  677. _ieeedoubtranslibname:    dc.b    'mathieeedoubtrans.library',0
  678.  
  679. _MathIeeeDoubBasBase:    dc.l     0
  680. _MathIeeeDoubTransBase:    dc.l     0
  681.  
  682. ;************************************
  683.  
  684.     section bss, dp_bss
  685.  
  686. _a6:            ds.l 1
  687.  
  688. ;************************************
  689.  
  690.     END
  691.